/**
* @author:kellen
* @contact:xiekellen@hotmail.com
* @company:achivo-gz
* @created on:
* @modified on:
*/

package com.sasis.dao.ibatis;

import java.util.List;

import com.sasis.dao.ibatis.BaseDaoiBATIS;
import com.sasis.model.PassengerState;
import com.sasis.dao.PassengerStateDao;

import org.springframework.orm.ObjectRetrievalFailureException;

public class PassengerStateDaoiBatis extends BaseDaoiBATIS implements PassengerStateDao {

    /**
     * @see com.sasis.dao.PassengerStateDao#getPassengerStates(com.sasis.model.PassengerState)
     */
    public List getPassengerStates(final PassengerState passengerState) {
          return getSqlMapClientTemplate().queryForList("getPassengerStates", passengerState);
    }

    /**
     * @see com.sasis.dao.PassengerStateDao#getPassengerState(Integer id)
     */
    public PassengerState getPassengerState(Integer id) {
        PassengerState passengerState = (PassengerState) getSqlMapClientTemplate().queryForObject("getPassengerState", id);

        if (passengerState == null) {
            throw new ObjectRetrievalFailureException(PassengerState.class, id);
        }

        return passengerState;
    }

    /**
     * @see com.sasis.dao.PassengerStateDao#savePassengerState(PassengerState passengerState)
     */    
    public void savePassengerState(final PassengerState passengerState) {
        Integer id = passengerState.getId();
        // check for new record
        if (id == null) {
            id = (Integer) getSqlMapClientTemplate().insert("addPassengerState", passengerState);
        } else {
            getSqlMapClientTemplate().update("updatePassengerState", passengerState);
        }
        if( id == null ) {
            throw new ObjectRetrievalFailureException(PassengerState.class, id);
        }
    }

    /**
     * @see com.sasis.dao.PassengerStateDao#removePassengerState(Integer id)
     */
    public void removePassengerState(PassengerState passengerState) {
        getSqlMapClientTemplate().update("deletePassengerState",  passengerState);
    }
}
